const postData = require('../../data/post-data.js');
const app = getApp();
// pages/posts/posts.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    posts: [],
    lunPosts : []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    //console.info(1);
    var that = this;
    app.getAccessToken().then(function(){
    var _token = wx.getStorageSync("token");
    //console.info(_token);
      wx.request({
        url: 'http://www.yd2021.com/index.php/API/news?token=' + _token, 
        success (res) {
          //console.info(res);
          that.setData({
            posts: res.data.data
          })
          postData.local_database = res.data.data;
          //console.info(postData.local_database);
        }
      }),
      wx.request({
        url: 'http://www.yd2021.com/index.php/API/banner?token=' + _token, 
        success (res) {
         // console.info(res);
          that.setData({
            lunPosts: res.data.data,
          })
        }
      })
    })
  },

  onPostTap: function(e) {
    const postId = e.currentTarget.dataset.postId;
   // console.info(postId);
    wx.navigateTo({
      url: `post-detail/post-detail?id=${postId}`
    })
  },

  onSwiperTap: function(e) {
    const postId = e.target.dataset.postId;
    //console.info(postId);
    wx.navigateTo({
      url: `post-detail/post-detail?id=${postId}`
    })
    
  }
})